define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    // add_url: 'order/add',
                    edit_url: 'order/edit',
                    // del_url: 'order/del',
                    // multi_url: 'order/multi',
                    // import_url: 'order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'pay_time',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        // {checkbox: true},
                         {field: 'out_trade_no', title: __('Out_trade_no'), operate: 'LIKE'},
                        // {field: 'id', title: __('Id')},
                        {field: 'order_type', title: __('订单类型'),searchList: {"1":'购买商品',"2":'余额充值（粮币）',"3":'购买vip '}, formatter: Table.api.formatter.normal},
                        {field: 'pay_type', title: __('支付类型'),searchList: {"1":'微信小程序',"2":'余额（粮币））',"3":'微信app支付 '}, formatter: Table.api.formatter.normal},
                        {field: 'u.dream_id', title: __('用户dream_id'),operate: 'LIKE'},
                        {field: 'w.dream_id', title: __('写手dream_id'),operate: 'LIKE'},
                       
                        // {field: 'orderNo', title: __('Orderno')},
                        // {field: 'fid', title: __('Fid')},
                        // {field: 'gid', title: __('Gid')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'day', title: __('天数')},
                        {field: 'num', title: __('数量')},
                        // {field: 'notes', title: __('Notes'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'cv_id', title: __('Cv_id')},
                        // 状态 0已创建 1已支付 2 已接单 3定稿中 4已完成 5已取消
                        // {field: 'cv_price', title: __('Cv_price'), operate:'BETWEEN'},
                        {field: 'm.status', title: __('状态'),searchList: {0:"已创建",1:"已支付",2:"已接单",3:"定稿中",4:"已完成",5:"已取消"}, formatter: Table.api.formatter.normal},
                        
                        {field: 'is_eval', title: __('评价'),searchList: {0:"未评",1:"已评"}, formatter: Table.api.formatter.normal},
                        // {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                         {field: 'end_time', title: __('截稿时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        
                        // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'del_time', title: __('Del_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'c_title', title: __('C_title'), operate: 'LIKE'},
                        // {field: 'c_desc', title: __('C_desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'c_word_count', title: __('C_word_count'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'task_id', title: __('Task_id')},
                        // {field: 'qr_time', title: __('Qr_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'com_time', title: __('Com_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'look_num', title: __('Look_num')},
                        // {field: 'app_type', title: __('App_type')},
                        // {field: 'ref_status', title: __('退款')},
                        {field: 'ref_status_fb', title: __('退款'),searchList: {0:"无",1:"部分",2:"全部"}, formatter: Table.api.formatter.normal},
                        // {field: 'ref_num', title: __('Ref_num')},
                        // {field: 'ref_money', title: __('Ref_money'), operate:'BETWEEN'},
                        {field: 'res_status', title: __('申诉'),searchList: {0:"无",1:"有"}, formatter: Table.api.formatter.normal},
                        // {field: 'res_status_cont', title: __('Res_status_cont'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'res_status_desc', title: __('Res_status_desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'is_zd', title: __('Is_zd')},
                        // {field: 'is_gai', title: __('Is_gai')},
                        // {field: 'is_gai_time', title: __('Is_gai_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'is_gai_time_add', title: __('Is_gai_time_add')},1未在截稿日期内上传异常 2截稿时间内未完成订单异常 
                        {field: 'is_abnormal', title: __('异常原因'),searchList: {0:"上传异常",1:"未完成"}, formatter: Table.api.formatter.normal},
                        {field: 'abnorma_time', title: __('异常时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                      {
                        field: 'buttons',
                        width: "120px",
                        title: __('状态'),
                        table: table,
                        events: Table.api.events.operate,
                        buttons: [
                            {
                                name: 'detail1',
                                text: __('完成订单含退款'),
                                title: __('完成订单含退款'),
                                classname: 'btn btn-xs btn-warning btn-dialog',
                                icon: 'fa',
                                visible: function(row){
                                        if(row.status != 5){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                },
                                url: 'order/edit?mtype=1',
                                callback: function (data) {
                                    $(".btn-refresh").trigger("click");
          
                                    Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                }
                            },
                            {
                                name: 'ajax',
                                text: __('退款订单'),
                                title: __('退款订单'),
                                classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                icon: 'fa',
                                url: 'order/edit?mtype=3',
                                confirm: '是否确认退款，退款后，订单金额将直接返回',
                                success: function (data, ret) {
                                         $(".btn-refresh").trigger("click");
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                                visible: function(row){
                                        if(row.status != 5){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },
                            {
                                name: 'ajax',
                                text: __('完成订单'),
                                title: __('完成订单'),
                                classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                icon: 'fa',
                                url: 'order/edit?mtype=2',
                                confirm: '是否确认完成订单，完成订单后订单佣金将下发到写手账户',
                                success: function (data, ret) {
                                         $(".btn-refresh").trigger("click");
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                                visible: function(row){
                                        if(row.status != 5){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },
                             {
                                name: 'detail1',
                                text: __('拒绝申诉'),
                                title: __('拒绝申诉'),
                                classname: 'btn btn-xs btn-warning btn-dialog',
                                icon: 'fa',
                                visible: function(row){
                                        if(row.status != 4 && row.res_status==1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                },
                                url: 'order/edit?mtype=5',
                                callback: function (data) {
                                    $(".btn-refresh").trigger("click");
          
                                    Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                }
                            },
                            // {
                            //     name: 'ajax',
                            //     text: __('拒绝申诉'),
                            //     title: __('拒绝申诉'),
                            //     classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
                            //     icon: 'fa',
                            //     url: 'order/res_qx?mtype=2',
                            //     confirm: '是否确认拒绝申诉',
                            //     success: function (data, ret) {
                            //          $(".btn-refresh").trigger("click");
                            //         //如果需要阻止成功提示，则必须使用return false;
                            //         //return false;
                                    
                            //     },
                            //     visible: function(row){
                            //             if(row.status <4 && row.res_status==1){
                            //                 return true;
                            //             }else{
                            //                 return false;
                            //             }
                            //     },
                            //     error: function (data, ret) {
                            //         console.log(data, ret);
                            //         Layer.alert(ret.msg);
                            //         return false;
                            //     }
                            // }
                            
                            
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            // Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
             bindevent: function () {
               Form.api.bindevent($("form[role=form]"), null, null, function () {
                
                    return true;
                });
            }
        }
    };
    return Controller;
});
